#ifndef MANAGER_H
#define MANAGER_H

#include "mainwindow.h"
#include "rentgenviewform.h"
#include "pacient.h"
#include <QPrinter>
#include "dbworker.h"
//#include "defs.h"

/* ---------------------------
  | Class for application managment.
  |     Singletone.
   -------------------------- */

class QDir;
class QSettings;

class Manager : public QObject
{
    Q_OBJECT

public:
    static void createInstance();
    static void deleteInstance();
    static Manager* instance();

    void setup();

    bool loadSettings();
    void saveSettings();

    MainWindow* mainWindow(){ return mMainWindow; }
    Pacient* pacient(){ return mPacient; }
    RentgenViewForm* rentgenViewForm();

    QString currentZipPath;
    QString currentUnpackedPath;
    QString fileInCurrent(const QString& fileName) const;

    bool isIconLoaded(const QString &src);
    void loadIcon(const QString& src);
    QPixmap* iconAt(const QString &src);
    void freeIcon(const QString& src);

    void setCurrentFolder(const QString& path);
    QString getCurrentFolder() const { return mCurrentFolder; }
    QDir curTempDir() const;

    QString copyImage(const QString& path);
    void printPacient();
    void clearCurrentFolder() const;
    void createPacient();

    DBWorker *dbWorker() { return dbw; }

    QStringList mOperationTypes;

public slots:
    void onPrintRequested(QPrinter *printer);

private:
    Manager();
    ~Manager();

    Pacient *mPacient;
    MainWindow *mMainWindow;
    RentgenViewForm *mRentgenViewForm;
    QSettings *mSettings;
    QMap<QString, QPixmap*> *mIcons;

    static Manager* mAppManager;

    QString mCurrentFolder;
    QSize winSize;
    QPoint winPos;
    QPrinter mPrinter;
    DBWorker *dbw;
};

#define App (Manager::instance())


#endif // MANAGER_H
